package 算法.LeetCode91.每日打卡题目;

import java.util.*;

/**
 * @author: 谢君臣
 * @create: 2021-02-21 13:14
 * @founction: XXXX
 */
public class day20 {
    public static void main(String[] args) {
     topKFrequent(new int[]{1},1);
    }
    public static int[] topKFrequent(int[] nums, int k) {
        Map<Integer,Integer> map = new HashMap<>();
        List list = new ArrayList<>();
        for (int num : nums) {
            int n = 1;
            if (map.containsKey(num)){
                n = map.get(num);
                map.put(num,++n);

            }
            else
                map.put(num, n);
            if (n==k)
                list.add(num);
        }
        int[] a = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            a[i] = (int) list.get(i);
        }
        return a;
    }
}
